package com.zt.rongda.salary.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zt.rongda.salary.model.SalaryEmpBasic;
import com.zt.rongda.salary.service.SalaryEmpBasicService;
import com.zt.servlet.ReqBean;
import com.zt.servlet.RequestAttribute;
import com.zt.servlet.Response;

import net.sf.json.JSONObject;

@Controller
@RequestMapping(value = "/salaryEmpBasic")
public class SalaryEmpBasicController {

    @Autowired
    private SalaryEmpBasicService salaryEmpBasicService;

    @RequestMapping(value = "/query")
    @ResponseBody
    
    public JSONObject query(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(salaryEmpBasicService.getTable(reqBean));
    }

    @RequestMapping(value = "/add")
    @ResponseBody
    
    public JSONObject add(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        salaryEmpBasicService.add(getSalaryEmpBasic(reqBean));
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/update")
    @ResponseBody
    
    public JSONObject update(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        salaryEmpBasicService.update(getSalaryEmpBasic(reqBean));
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    
    public JSONObject delete(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        salaryEmpBasicService.delete(reqBean.getInfo("empId"));
        return Response.responseSuccess();
    }

    /**
    * 从表单获取对象
    *
    * @param reqBean
    * @return
    */
    private SalaryEmpBasic getSalaryEmpBasic(ReqBean reqBean) {
        SalaryEmpBasic salaryEmpBasic = new SalaryEmpBasic();
        salaryEmpBasic.setEmpId(reqBean.getInfo("empId"));
        salaryEmpBasic.setBaseSalary(reqBean.getInfoDouble("baseSalary"));
        salaryEmpBasic.setWorkingAgeSubsidy(reqBean.getInfoDouble("workingAgeSubsidy"));
        salaryEmpBasic.setPositionSalary(reqBean.getInfoDouble("positionSalary"));
        salaryEmpBasic.setSocialSecurity(reqBean.getInfoDouble("socialSecurity"));
        salaryEmpBasic.setAttendance(reqBean.getInfoDouble("attendance"));
        salaryEmpBasic.setOperator(reqBean.getUserId());
        salaryEmpBasic.setRemark(reqBean.getInfo("remark"));
        return salaryEmpBasic;
    }

}